<template>
    <div>
        <Form :model="form" label-position="left" :label-width="120">
            <FormItem label="填报部门"  prop="title">
                <Input v-model="form.bmA" style="width: 25%;" disabled></Input>
            </FormItem>
        </Form>
        <Form :model="formLeft" label-position="left" :label-width="120">
            <FormItem label="领导小组" :required="true">
                <Input v-model="formLeft.framework" maxlength="100" :show-word-limit="true" type="textarea" style="width: 700px" />
            </FormItem>
            <FormItem label="工作专班" :required="true" :label-width="120">
                <Row style="margin-top: 3px">
                    <Col>
                        业务单位组
                    </Col>
                </Row>
                <Row style="margin-top: 3px">
                    <Col span="3">
                        <Input v-model="formLeft.fenguan_name" style="width: 140px">
                            <span slot="prepend" >分管领导</span>
                        </Input>
                    </Col>
                    <Col span="3">
                        <Input v-model="formLeft.fenguan_phone" style="width: 130px" placeholder="电话"/>
                    </Col>
                    <Col span="3">
                        <Input v-model="formLeft.chuzhanga_name" style="width: 140px">
                            <span slot="prepend" >处长A</span>
                        </Input>
                    </Col>
                    <Col span="3">
                        <Input v-model="formLeft.chuzhanga_phone" style="width: 130px" placeholder="电话"/>
                    </Col>
                    <Col span="3">
                        <Input v-model="formLeft.chuzhangb_name" style="width: 140px">
                            <span slot="prepend" >处长B</span>
                        </Input>
                    </Col>
                    <Col span="3">
                        <Input v-model="formLeft.chuzhangb_phone" style="width: 130px" placeholder="电话"/>
                    </Col>
                    <Col span="3">
                        <Input v-model="formLeft.ywlian_name" style="width: 140px">
                            <span slot="prepend" >联络员</span>
                        </Input>
                    </Col>
                    <Col span="3">
                        <Input v-model="formLeft.ywlian_phone" style="width: 130px" placeholder="电话"/>
                    </Col>
                </Row>
                <Row style="margin-top: 3px">
                    <Col>
                        派驻纪检组(纪委)工作推进组
                    </Col>
                </Row>
                <Row style="margin-top: 3px">
                    <Col span="3">
                        <Input v-model="formLeft.pzzz_name" style="width: 140px">
                            <span slot="prepend" >组长</span>
                        </Input>
                    </Col>
                    <Col span="3">
                        <Input v-model="formLeft.pzzz_phone" style="width: 130px" placeholder="电话"/>
                    </Col>
                    <Col span="3">
                        <Input v-model="formLeft.pzlly_name" style="width: 140px">
                            <span slot="prepend" >联络员</span>
                        </Input>
                    </Col>
                    <Col span="3">
                        <Input v-model="formLeft.pzllu_phone" style="width: 130px" placeholder="电话"/>
                    </Col>
                </Row>
                <Row style="margin-top: 3px">
                    <Col>
                        技术保障组
                    </Col>
                </Row>
                <Row style="margin-top: 3px">
                    <Col span="3">
                        <Input v-model="formLeft.jishu_name" style="width: 140px">
                            <span slot="prepend" >组长</span>
                        </Input>
                    </Col>
                    <Col span="3">
                        <Input v-model="formLeft.jishu_phone" style="width: 130px" placeholder="电话"/>
                    </Col>
                </Row>
            </FormItem>
            <h3 style="margin-left: 10px;margin-bottom: 10px">工作方案</h3>
            <FormItem label="方案名称" :required="true">
                <Input v-model="formLeft.programme_name" maxlength="200" :show-word-limit="true"  style="width: 600px" />
            </FormItem>
            <FormItem label="制定时间" :required="true">
                <DatePicker type="date" style="width: 200px" v-model="formLeft.formulate_date" />
            </FormItem>
            <FormItem label="附件上传" :required="true">
                <wl-upload-oss-files
                        v-model="formLeft.programme_work"
                        :maxNum="50"
                        uploadType="hadoop"
                        uploadStyle="other"
                        uploadUrl='http://218.60.17.11:33685/api/ac/file/fileCommonService/upLoadFiles'
                        getSignUrl="/api/ac/jwork/getHadoopService/getSign"
                        fileName="origin"
                        :beforeUploadFilter="uploadFilter"
                        :format="['doc','docx','pdf','xls','xlsx']"
                        fileDir="/jov/">
                </wl-upload-oss-files>
                <span style="color:#9ea7b4;font-size: 12px">请上传《工作方案》等相关材料信息，支持PDF，Word和Excel</span>
            </FormItem>
        </Form>
        <Row type="flex" justify="center" class="code-row-bg">
            <Col :gutter="16" span="2">
                <Button type="primary" @click="a">保存</Button>
            </Col>
            <Col span="7" >
                <Button type="success" @click="ok()" :disabled ="nn">完成，并提报“搭建组织机构”信息</Button>
            </Col>
        </Row>
        <Row type="flex" justify="center" class="code-row-bg" style="margin-top: 20px">
            <Col span="10">
                <div style="color:#9ea7b4">
                    点击【完成，并“搭建组织机构”信息】按钮后，仍可继续完善相关信息
                </div>
            </Col>
        </Row>
    </div>
</template>

<script>
import { insertOrganization, insertZlStateOrganization, getCountStateList, updateOrganization, countOrganizationState } from '@/api/user'

export default {
  name: 'test',
  data () {
    return {
      form: {
        bmA: ''
      },
      tm: '',
      companyCode: '',
      select_type: '',
      formLeft: {
        framework: '',
        programme_work: '',
        fenguan_name: '',
        fenguan_phone: '',
        chuzhanga_name: '',
        chuzhanga_phone: '',
        chuzhangb_name: '',
        chuzhangb_phone: '',
        ywlian_name: '',
        ywlian_phone: '',
        pzzz_name: '',
        pzzz_phone: '',
        pzlly_name: '',
        pzllu_phone: '',
        jishu_name: '',
        jishu_phone: '',
        programme_name: '',
        formulate_date: ''
      },
      nn: false
    }
  },
  methods: {
    async init () {
      countOrganizationState().then(ret => {
        console.log(ret.data.data, 'ret!!!!!!########')
        if (ret.data.data === 0 || ret.data.data === '') {
          this.select_type = '0'
        } else {
          this.select_type = '1'
        }
      })
      // this.formValidate = this.$route.params.aa || {}
      // this.tm = this.$store.state.user.severUserInfo.data.company_name
      // console.log(tm)
    },
    uploadFilter (file, uploadList, filterReturn) {
      let isExit = false
      if (uploadList.length > 0) {
        uploadList.forEach(item => {
          if (item.url.indexOf(file.name) !== -1) {
            isExit = true
          }
        })
      }
      if (isExit) {
        this.errMsgAction(file.name, '【文件已经存在】')
        return { errcode: false, selfShow: true }
      }
      return { errcode: true }
    },
    a () {
      if (this.formLeft.formulate_date === '' || this.formLeft.formulate_date === undefined) {
        this.$Message.error('制定时间不能为空！！！！！！！！！！')
      } else {
        console.log(this.formLeft, '表单')
        let time = new Date(this.formLeft.formulate_date)
        this.formLeft.formulate_date = time.getFullYear() + '-' + (time.getMonth() + 1) + '-' + time.getDate()
        this.formLeft.select_type = this.select_type
        console.log(this.formLeft.select_type, '!!!!!')
        if (this.formLeft.id === undefined) {
          insertOrganization(this.formLeft).then(ret => {
            if (ret.data.errcode === 0) {
              this.$Message.success('成功')
              this.$router.push({
                path: 'organizations'
              })
            } else if (ret.data.errcode === 9999) {
              this.$Message.error('不能重复添加')
            }
          })
        } else {
          this.formLeft.select_type = this.select_type
          console.log(this.formLeft.select_type, '!!!!!')
          updateOrganization(this.formLeft).then(ret => {
            if (ret.data.errcode === 0) {
              this.$Message.success('修改成功')
              this.$router.push({
                path: 'organizations'
              })
            } else if (ret.data.errcode === 9999) {
              this.$Message.error('修改失败')
            }
          })
        }
      }
    },

    insert () {
    },
    show (index) {
      this.$router.push({
        path: 'IdeologicalCognitionf'
      })
    },
    ok () {
      if (this.formLeft.id === undefined) {
        this.formLeft.select_type = '1'
        console.log(this.formLeft.select_type, '!!!!!')
        insertOrganization(this.formLeft).then(ret => {
          if (ret.data.errcode === 0) {
            this.$Message.success('成功')
            this.$router.push({
              path: 'organizations'
            })
          } else if (ret.data.errcode === 9999) {
            this.$Message.error('不能重复添加')
          }
        })
      } else {
        this.formLeft.select_type = '1'
        console.log(this.formLeft.select_type, '!!!!!')
        updateOrganization(this.formLeft).then(ret => {
          if (ret.data.errcode === 0) {
            this.$Message.success('成功')
            this.$router.push({
              path: 'organizations'
            })
          } else if (ret.data.errcode === 9999) {
            this.$Message.error('失败')
          }
        })
      }
      // let state = { state: 'b', 'step': '组织机构' }
      // insertZlStateOrganization(state).then(ret => {
      //   if (ret.data.errcode === 0) {
      //     getCountStateList({ 'step': '组织机构' }).then(ret => {
      //       let a = ret.data.data
      //       if (a[0].state === 'b') {
      //         this.nn = true
      //       }
      //       console.log('bz', a[a.length - 1])
      //     })
      //   }
      // })
      let state = { state: 'b', 'step': '组织机构' }
      insertZlStateOrganization(state).then(ret => {
        if (ret.data.errcode === 0) {
          getCountStateList({ 'step': '组织机构' }).then(ret => {
            let a = ret.data.data
            console.log(a, 'a')
            if (a[0].state === 'b') {
              this.nn = true
            }
            console.log('bz', a[0])
          })
        }
      })
    }
  },

  watch: {
  },

  mounted () {
    if (this.$route.query.a !== undefined) {
      this.formLeft = this.$route.query.a
      this.form.bmA = this.$route.query.a.department_name
      this.companyCode = this.$route.query.a.company_code
    } else {
      this.form.bmA = this.$store.state.user.severUserInfo.data.company_name
      console.log(this.tm)
    }
    getCountStateList({ 'step': '组织机构', companyCode: this.companyCode }).then(ret => {
      // console.log('bztj', ret.data.data[0].state)
      if (ret.data.data.length === 0) {
        return
      }
      if (ret.data.data[0].state === 'b') {
        this.nn = true
      }
    })
    this.init()
  }

}
</script>

<style scoped>
    .demo-upload-list{
        display: inline-block;
        width: 60px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border: 1px solid transparent;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
        position: relative;
        box-shadow: 0 1px 1px rgba(0,0,0,.2);
        margin-right: 4px;
    }
    .demo-upload-list img{
        width: 100%;
        height: 100%;
    }
    .demo-upload-list-cover{
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0,0,0,.6);
    }
    .demo-upload-list:hover .demo-upload-list-cover{
        display: block;
    }
    .demo-upload-list-cover i{
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }
</style> c
